<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>消息供应商管理</title>
</head>
<body>
  <div class="layui-fluid">   
    <div class="layui-card">
      <!-- 查询区域  -->
      <div id="query-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">供应商编号</label>
            <div class="layui-input-inline">
              <input type="text" name="spartnerCode" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">供应商名称</label>
            <div class="layui-input-inline">
              <input type="text" name="spartnerName" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <shiro:hasPermission name="QUERY_MSGPARTNER">
	          <div class="layui-inline">
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-msg-partner-search">
	              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
	            </button>
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
	              <i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
	            </button>
	          </div>
          </shiro:hasPermission>
        </div>
      </div>
  	  <!-- 按钮区域  -->
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
        	<shiro:hasPermission name="INSERT_MSGPARTNER">
          		<button class="layui-btn layuiadmin-btn-admin " data-type="add">
          	 		<i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增
          		</button>
          	</shiro:hasPermission>
          	<shiro:hasPermission name="ZPK_MSGPARTNER">
				<button class="layui-btn layuiadmin-btn-admin" onclick="refreshCache()">
          	 		<i class="layui-icon layui-icon-refresh-3 layuiadmin-button-btn"></i>刷新缓存
          		</button>
			</shiro:hasPermission>
        </div>
        <!-- 数据表单 -->
        <table id="LAY-msg-partner-manage" lay-filter="LAY-msg-partner-manage"></table>
        
        <div class="layui-form" lay-filter="add_from" id="add_from" style="padding: 20px 30px 0 0;display:none">
		    <div class="layui-form-item">
		      <label class="layui-form-label">供应商编号</label>
		      <div class="layui-input-block">
		        <input type="text" name="spartnerCode" maxlength="50" lay-verify="required" placeholder="请输入供应商编号" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">供应商类型</label>
		      <div class="layui-input-block">
		      	<infopub:select  id="add_itype" name="itype" type="dic" groupNo="A00010013">
				</infopub:select>
		      </div>
		    </div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">名称</label>
			    <div class="layui-input-block">
			      <input type="text" name="spartnerName" maxlength="50" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
			    </div>
		  	</div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">账户名</label>
			    <div class="layui-input-block">
			      <input type="text" name="spartnerAccName" maxlength="50" lay-verify="required" placeholder="请输入账户名" autocomplete="off" class="layui-input">
			    </div>
		  	</div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">密码</label>
			    <div class="layui-input-block">
			      <input type="text" name="spartnerAccPassword" maxlength="50" lay-verify="required" placeholder="请输入账户名" autocomplete="off" class="layui-input">
			    </div>
		  	</div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">描述</label>
		      <div class="layui-input-block">
		        <textarea name="spartnerDesc" maxlength="200" lay-verify="required" placeholder="请输入描述" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">扩展信息</label>
		      <div class="layui-input-block">
		        <textarea name="spartnerExtInfo" maxlength="500" lay-verify="required" placeholder="请输入扩展信息" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="add_from_submit" id="add_from_submit" value="确认">
		    </div>
	  	</div>
	  	
	  	<!-- 编辑编号配置 -->
        <div class="layui-form" lay-filter="edit_from" id="edit_from" style="padding: 20px 30px 0 0;display:none">
        	<input type="hidden" name="id" />
		    <div class="layui-form-item">
		      <label class="layui-form-label">供应商编号</label>
		      <div class="layui-input-block">
		        <input type="text" name="spartnerCode" maxlength="50" lay-verify="required" placeholder="请输入供应商编号" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">供应商类型</label>
		      <div class="layui-input-block">
		      	<infopub:select name="itype" type="dic" groupNo="A00010013">
				</infopub:select>
		      </div>
		    </div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">名称</label>
			    <div class="layui-input-block">
			      <input type="text" name="spartnerName" maxlength="50" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
			    </div>
		  	</div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">账户名</label>
			    <div class="layui-input-block">
			      <input type="text" name="spartnerAccName" maxlength="50" lay-verify="required" placeholder="请输入账户名" autocomplete="off" class="layui-input">
			    </div>
		  	</div>
		    <div class="layui-form-item">
		    	<label class="layui-form-label">密码</label>
			    <div class="layui-input-block">
			      <input type="text" name="spartnerAccPassword" maxlength="50" lay-verify="required" placeholder="请输入账户名" autocomplete="off" class="layui-input">
			    </div>
		  	</div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">描述</label>
		      <div class="layui-input-block">
		        <textarea name="spartnerDesc" maxlength="200" lay-verify="required" placeholder="请输入描述" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">扩展信息</label>
		      <div class="layui-input-block">
		        <textarea name="spartnerExtInfo" maxlength="500" lay-verify="required" placeholder="请输入扩展信息" class="layui-textarea"></textarea>
		      </div>
		    </div>
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="edit_from_submit" id="edit_from_submit" value="确认">
		    </div>
	  	</div>
      </div>
    </div>
  </div>

  <script>
  	//json
 	var typeJSON = <infopub:dicJson groupNo="A00010013" />;
  	layui.config({
    	base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index' //主入口模块
  	}).use(['index', 'table', 'set', 'transfer'], function(){
    	var $ = layui.$
    	,form = layui.form
    	,table = layui.table;
    	// 表单
    	table.render({
      		elem: '#LAY-msg-partner-manage'
      		,url: basePath + '/msgPartner/query' //请求数据接口
      		,cols: [[
        		{type: 'checkbox', fixed: 'left'}
        		,{field: 'spartnerCode', title: '供应商编号'}
        		,{field: 'itype',title: '供应商类型',templet:function(d){
        				return typeJSON[d.itype];
        			}
        		}
        		,{field: 'spartnerName',title: '名称'}
        		,{field: 'spartnerAccName',title: '账户名'}
        		,{field: 'spartnerAccPassword',title: '密码'}
        		,{field: 'spartnerDesc',title: '描述'}
        		,{field: 'spartnerExtInfo',title: '扩展信息'}
        		,{title: '操作', width: 150, align:'center', fixed: 'right', templet: function(d){
			      	  	var optStr ="";
			      	  	<shiro:hasPermission name="UPDATE_MSGPARTNER"> 
				      		optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>';
			  	  	  	</shiro:hasPermission>
			  	  	  	<shiro:hasPermission name="DELETE_MSGPARTNER">
			  	    		 optStr += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
			  		  	</shiro:hasPermission>
			  		  	return optStr;
	        		}
        		}
      		]]
      	,page: true
      	,limit: 10
    });
    
    <shiro:hasPermission name="QUERY_MSGPARTNER">
	    //监听搜索
	    form.on('submit(LAY-msg-partner-search)', function(data){
	      //执行重载
	      table.reload('LAY-msg-partner-manage', {page: {curr: 1},
	        where: trimData(data)
	      });
	    });
	 	//重置清空
	    form.on('submit(LAY-user-back-reset)', function(data){
	    	reset_form('query-form');
	    });
    </shiro:hasPermission>
    
    // 监听操作列
    table.on('tool(LAY-msg-partner-manage)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
          layer.confirm('确定删除？',{icon:3, title :'提示'}, function(index){
          	$.ajax({
  				type : 'post',
  				url : basePath + '/msgPartner/delete?checkboxId=' + data.id,
  				success:function(result){
  					if(result.success){
  						table.reload('LAY-msg-partner-manage'); //数据刷新
  						layer.close(index);
  					}else{
  						layer.msg(result.msg,{icon: 7});
  				  	}
  				}
  			});
          });
      } else if(obj.event === 'edit'){
      	form.val('edit_from',data); // 填充原值
      	layer.open({
            type: 1
            ,title: '编辑消息供应商'
            ,content: $('#edit_from')
            ,area: layui.admin.screen() < 2 ? ['80%', '630px'] : ['420px','630px']
            ,btn: ['确定', '取消']
            ,btnAlign: 'c'
            ,yes: function(index, layero){
          	  var submitID = 'edit_from_submit'
          		  ,submit = layero.contents().find('#'+ submitID);
          	  //监听提交
          	  form.on('submit('+ submitID +')', function(data){
                var field = data.field; //获取提交的字段
                //提交 Ajax 成功后，静态更新表格中的数据
                $.ajax({
                    type : 'post',
  					url : basePath + '/msgPartner/update',
                    data: field,
  					success:function(result){
  						if(result.success){
                			table.reload('LAY-msg-partner-manage'); //数据刷新
                			layer.close(index); //关闭弹层
                			clean_form('edit_from');//清空表单
  						}else{
  							layer.msg(result.msg,{icon: 7});
  					  	}
  					}
                });
              });  
              submit.trigger('click');
            }
          });
        }
    });
    
    // 按钮事件
    var active = {
      add: function(){
          layer.open({
        	  type: 1
        	  ,title: '添加消息供应商'
        	  ,content: $('#add_from')
        	  ,area: layui.admin.screen() < 2 ? ['80%', '630px'] : ['420px','630px']
        	  ,btn: ['确定', '取消']
        	  ,btnAlign: 'c'
        	  ,yes: function(index, layero){
        		  var submitID = 'add_from_submit'
            		,submit = layero.contents().find('#'+ submitID);
        		  //监听提交
        		  form.on('submit('+ submitID +')', function(data){
        			  var field = data.field; //获取提交的字段
        			  //提交 Ajax 成功后，静态更新表格中的数据
        			  $.ajax({
        				  type : 'post',
        				  url : basePath + '/msgPartner/insert',
        				  data: field,
        				  success:function(result){
        					  if(result.success){
        						  table.reload('LAY-msg-partner-manage'); //数据刷新
        						  layer.close(index); //关闭弹层
        						  clean_form("add_from");//清空表单
        					  }else{
        						  layer.msg(result.msg,{icon: 7});
        					  }
        				  }
              		 });
            	});  
            submit.trigger('click');
          }
        }); 
      }
    }  
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  
	//刷新缓存
	function refreshCache(){
		layui.$.ajax({
		  type : 'post',
		  url : '${ctx}/zkpPath/mgcPartnerInfo',
		  success:function(result){
			  if(result.success){
				  layer.alert(result.msg, {icon:1});
			  }else{
				  layer.msg(result.msg, {icon:7});
			  }
		  }
	  });
	}
  </script>
</body>
</html>

